Contents

%run set_theme.ipynb
import plotly.express as px
import pandas as pd
from plotly.offline import init_notebook_mode

init_notebook_mode()
df = pd.read_parquet('../data/SO_2014_2022.pq')

avg_work_experience = df.groupby('Gender')['YearsCodePro'].mean().reset_index()

fig = px.bar(
    avg_work_experience,
    x='Gender',
    y='YearsCodePro',
    color='Gender',
    labels={
        'Gender': 'Gender',
        'YearsCodePro': 'Average years of work experience'
    },
    color_discrete_map={
        'male': '#5b6fec',
        'female': '#f854ee'
    },
    title='Average Work Experience By Gender<br><sup>Male survey respondents generally have more professional work experience</sup>',
    width=790,
)

fig.update_traces(
    width=0.4,
    showlegend=False,
    hoverlabel={'font_color': 'white', 'bordercolor': 'white'}
)

fig.update_layout(
    margin={'l': 80, 'b': 120, 't': 100}
)

for trace in fig.data:
    trace.hovertemplate = '<b>' + trace.name.capitalize() + '</b><br>Average work experience: %{y:.1f} years<extra></extra>'

fig.add_annotation(x=-0.07, y=-0.32,
                   xref="paper", yref="paper",
                   align='left',
                   xanchor='left', yanchor='bottom',
                   showarrow=False,
                   text='The bars represent the average work experience in years for both genders.<br>' +
                        'Hover over them to see the precise value.')

fig.show()